<?php
/**
 * @file
 * @package mileage
 * @version $Id$
**/

if (!defined('XOOPS_ROOT_PATH')) {
    exit;
}

require_once MILEAGE_TRUST_PATH . '/class/AbstractListAction.class.php';

/**
 * Mileage_Admin_MileListAction
**/
class Mileage_Admin_MileListAction extends Mileage_AbstractListAction
{
	/**
	 * &_getHandler
	 * 
	 * @param   void
	 * 
	 * @return  Mileage_MileHandler
	**/
	protected function &_getHandler()
	{
		$handler =& $this->mAsset->getObject('handler', 'mile');
		return $handler;
	}

	/**
	 * &_getFilterForm
	 * 
	 * @param   void
	 * 
	 * @return  Mileage_Admin_MileFilterForm
	**/
	protected function &_getFilterForm()
	{
		// $filter =& new Mileage_Admin_MIleFilterForm();
		$filter =& $this->mAsset->getObject('filter', 'mile', true);
		$filter->prepare($this->_getPageNavi(), $this->_getHandler());
		return $filter;
	}

	/**
	 * _getBaseUrl
	 * 
	 * @param   void
	 * 
	 * @return  string
	**/
	protected function _getBaseUrl()
	{
		return './index.php?action=MileList';
	}

	/**
	 * executeViewIndex
	 * 
	 * @param   XCube_RenderTarget  &$render
	 * 
	 * @return  void
	**/
	public function executeViewIndex(&$render)
	{
		// XCAT category
		$cattree = Mileage_Utils::getXcat($this->mAsset->mDirname);
		$cat = array();
		if (!empty($cattree)) {
			foreach ($cattree as $k => $v) {
				$cat[$v['cat_id']] = $v;
			}

			foreach ($this->mObjects as $key => $obj) {
				$group = $obj->get('group');
				if (!empty($group)) {
					$group = trim($group, '[]');
					$group_arr = explode('][', $group);
					$this->mObjects[$key]->group_arr = $group_arr;
				}
			}
		}

		$render->setTemplateName('mile_list.html');
		$render->setAttribute('objects', $this->mObjects);
		$render->setAttribute('cat', $cat);
		$render->setAttribute('pageNavi', $this->mFilter->mNavi);
	}

}
